<template>
	<view>
		<cu-custom bgColor="bg-gradual-red text-white" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">{{scoreName}}明细({{total}})</block>
		</cu-custom>
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :up="upOption">
		<view class="cu-card article">
			<view class="cu-item shadow">
				<view class="flex justify-between align-center padding solid-bottom">
					<text class="text-grey text-df text-left">行为</text>
					<text class="text-grey text-df text-right">分值变动</text>
				</view>
				<view v-for="(item,index) in dataList" :key="index">
					<view :class="'flex justify-between align-center padding-left padding-right padding-top '+[index==dataList.length-1?'':'solid-bottom padding-bottom']">
						<text class="text-grey text-sm text-left">{{item.desc}}</text>
						<text class="text-gray text-df text-right">+{{item.score}}</text>
					</view>
				</view>
			</view>
		</view>
		</mescroll-body>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import { checkLogin } from '@/js_sdk/checkLogin.js'
	import { getUserScoreDetailList } from '@/api/api.js'
	import config from '@/api/config.js'
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				total:0,
				dataList: [],
				upOption: {
					page: {
						size: 30 // 每页数据的数量,默认10
					},
					textNoMore:config.customNoMore,
					noMoreSize: 1, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						tip: '暂无相关数据'
					}
				},
				
			}
		},
		computed: {
			scoreName() {
				return config.scoreName
			}
		},
		onShow(){
			checkLogin()
		},
		methods: {
			downCallback() {
				if (this.mescroll) {
					this.mescroll.resetUpScroll()
				}
			},
			upCallback(page) {
				let pageIndex = page.num - 1
				let pageSize = page.size
				this.getDataList(pageIndex, pageSize)
			},
			getDataList(pageIndex, pageSize) 
			{
				getUserScoreDetailList(pageIndex, pageSize).then(res=>{
					let pageList = res.data.list
					this.total = res.data.total
					console.log(pageList)
					if (pageIndex == 0) {
						this.dataList = pageList
					}else{
					    this.dataList =	this.dataList.concat(pageList);
					}
					let hasNext = pageList.length >= pageSize
					if (this.mescroll) {
						this.mescroll.endSuccess(pageList.length, hasNext);
					}
				}).catch(error=>{
					if (this.mescroll) {
						this.mescroll.endErr()
					}
				})
			}
		},
	}
</script>

<style scoped>

</style>